package service.impl;

import core.BusinessException;
import dao.LoginDao;
import domain.Student;
import service.ILoginService;

import java.sql.SQLException;

public class LoginServiceImpl implements ILoginService {
    private final LoginDao loginDao;

    public LoginServiceImpl(LoginDao loginDao) {

        this.loginDao = loginDao;
    }

    @Override
    public Student login(String student_id, String student_password) throws SQLException {
        Student target = this.loginDao.getStudentsByStudent_id(student_id);
        if (target == null) {
            throw new BusinessException(500, "您输入的用户不存在！");
        }

//        if (!target.getStudentPassword().equals(MD5Utils.md5(MD5Utils.md5(student_password)))) {
            if (!target.getStudentPassword().equals(student_password)) {
            throw new BusinessException(500, "您输入的密码有误");
        }

        return target;
    }

    @Override
    public int register(Student student) {
        return 0;
    }
}
